package com.zboin.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zboin.ucenter.mapper.RoleMapper;
import com.zboin.ucenter.model.Role;
import com.zboin.ucenter.service.RoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhboom
 * @date 2025/8/4 23:34
 */
@Service
public class RoleServiceImpl implements RoleService {

    private final RoleMapper roleMapper;

    public RoleServiceImpl(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @Override
    public Role getRoleById(Integer roleId) {
        return roleMapper.selectById(roleId);
    }

    @Override
    public Role getRoleByName(String roleName) {
        return roleMapper.selectOne(new QueryWrapper<Role>().eq("role_name", roleName));
    }

    @Override
    public List<Role> getRoleByGroupId(Integer groupId) {
        return roleMapper.selectList(new QueryWrapper<Role>().eq("group_id", groupId));
    }

    @Override
    public List<Role> getRoleByUserId(Integer userId) {
        return roleMapper.getRoleByUserId(userId);
    }

    @Override
    public int addRole(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int updateRole(Role role) {
        return roleMapper.updateById(role);
    }

    @Override
    public int deleteRole(Integer roleId) {
        return roleMapper.deleteById(roleId);
    }
}
